/*
 * @Description: 
 * @Version: 0.0.0
 * @Autor: 源
 * @Date: 2022-10-21 13:44:01
 * @LastEditors: 源
 * @LastEditTime: 2022-11-01 09:53:05
 * @FilePath: \pnpm-v3-ts-ui\docs\vite.config.ts
 */

import { defineConfig } from 'vite'
import type { UserConfig, ConfigEnv } from 'vite'
import { resolve } from "path";
//svg
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"
export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
  const isServe = command === 'serve'
  const root = process.cwd()
  return {
    plugins: [
      createSvgIconsPlugin({
        // 指定需要缓存的图标文件夹
        iconDirs: [resolve(root, 'svgs')],
        // 指定symbolId格式
        symbolId: 'lm-[dir]-[name]'
      })
    ],
    build: {
      terserOptions: {
        compress: {
          drop_console: !isServe,
          drop_debugger: !isServe,
        },
        output: {
          comments: !isServe,
        },
      }
    },
    resolve: {
      alias: {
        '@/api': resolve(__dirname, 'api'),//定义路径别名为@
      },
    },
    css: {
      // 全局变量+全局引入less+配置antdv主题色
      preprocessorOptions: {}
    },
  }
})
